package gatperdut.chato.core.threads;

import gatperdut.chato.constants.CSConstantsMovement.Direction;
import gatperdut.chato.core.characters.BaseController;

import java.util.Random;

public class FleeThread extends Thread {

    private final BaseController baseController;

    private Direction desiredDirection;

    public FleeThread( BaseController baseController, Direction desiredDirection ) {
        this.baseController = baseController;
        this.setDesiredDirection( desiredDirection );
    }

    @Override
    public void run() {
        Random random = new Random();
        while ( true ) {
            try {
                sleep( random.nextInt( 7 ) * 1000 + 4000 );
            }
            catch ( InterruptedException e ) {
                getBaseController().getCombatController().setFleeThread( null );
                return;
            }
            getBaseController().getEchoes().txFlee();
        }
    }

    public Direction getDesiredDirection() {
        return desiredDirection;
    }

    public void setDesiredDirection( Direction desiredDirection ) {
        this.desiredDirection = desiredDirection;
    }

    public BaseController getBaseController() {
        return baseController;
    }

}
